<!doctype html>
<html>
<head>
  <title>Test simple fill mode on transform</title>
  <style>
    .box {
      position: relative;
      left: 10px;
      top: 10px;
      height: 100px;
      width: 100px;
      transform: translate3d(100px, 0, 0);
      animation-delay: 0.1s;
      animation-duration: 0.1s;
      animation-timing-function: linear;
    }
    .started .box {
      animation-name: anim;
    }
    @keyframes anim {
        from { transform: translate3d(200px, 0, 0); }
        to   { transform: translate3d(300px, 0, 0); }
    }
    #a {
      background-color: #f99;
      animation-fill-mode: both;
      animation-iteration-count: 2;
      animation-direction: reverse;
    }
    #b {
      background-color: #999;
      animation-fill-mode: both;
      animation-iteration-count: 2;
      animation-direction: alternate-reverse;
    }
  </style>
  <script src="../resources/animation-test-helpers.js"></script>
  <script>
    const numAnims = 1;
    var animsFinished = 0;
    const allowance = 5;
    const expectedValues = [
      {id: "a", start: 300, end: 200},
      {id: "b", start: 300, end: 300}
    ];
    var result = "";

    if (window.testRunner) {
        testRunner.dumpAsText();
        testRunner.waitUntilDone();
    }

    function animationEnded(event) {
        if (++animsFinished == numAnims) {
          // Give the animation a chance to be 1 frame into the after phase.
          requestAnimationFrame(endTest);
        }
    };

    function endTest() {

        for (var i = 0; i < expectedValues.length; i++) {
            var realValue = getPropertyValue("transform", expectedValues[i].id);
            var expectedValue = expectedValues[i].end;
            if (comparePropertyValue(realValue, expectedValue, allowance, 4))
                result += "PASS";
            else
                result += "FAIL";
            result += " - end of animation - id: " + expectedValues[i].id + " expected: " + expectedValue + " actual: " + realValue + "<br>";
        }
        document.getElementById('result').innerHTML = result;

        if (window.testRunner)
            testRunner.notifyDone();
    }

    window.onload = function () {
      document.addEventListener("animationend", animationEnded, false);
      document.body.classList.add('started');
      for (var i = 0; i < expectedValues.length; i++) {
          var realValue = getPropertyValue("transform", expectedValues[i].id);
          var expectedValue = expectedValues[i].start;
          if (comparePropertyValue(realValue, expectedValue, allowance, 4))
              result += "PASS";
          else
              result += "FAIL";
          result += " - start of animation - id: " + expectedValues[i].id + " expected: " + expectedValue + " actual: " + realValue + "<br>";
      }
    };

  </script>
</head>
<body>
This test performs an animation of the transform property with different
fill modes. It animates over 0.1 second with a 0.1 second delay.
It takes snapshots at document load and the end of the animations.
<div id="a" class="box">
  Both Iterate - Reverse
</div>
<div id="b" class="box">
  Both Iterate - Alternate Reverse
</div>
<div id="result">
</div>
</body>
</html>
